package com.blb.utils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.blb.entity.User;

public class SessionUtils {
	/**
	 * 获取当前登录的用户ID
	 * @return
	 */
	public static String getUserId(){
		return getUser().getId();
	}
	/**
	 * 获取用户名
	 * @return
	 */
	public static String getUserName(){
		return getUser().getUsername();
	}
	/**
	 * 获取当前登录用户
	 * @return
	 */
	public static User getUser(){
		HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
		HttpSession session = request.getSession();
		return (User) session.getAttribute("user");
	}

}
